package com.amos.think.adapter.web;


import com.alibaba.cola.dto.Response;
import com.amos.think.api.IUserMongoService;
import com.amos.think.domain.user.UserEntity;
import com.amos.think.dto.UserRegisterCmd;
import com.amos.think.dto.data.ReqUserDTO;
import com.amos.think.dto.data.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/mongo")
@Slf4j
public class UserMongoController {

    @Autowired
    private IUserMongoService iUserMongoService;

    @PostMapping("/register")
    public Response register(@RequestBody UserRegisterCmd userRegisterCmd){
        iUserMongoService.register(userRegisterCmd);
        log.info("数据更新成功");
        return Response.buildSuccess();
    }
    /**
     * 获取所有用户信息
     */
    @PostMapping("/getAllUsers")
    public List<UserVO> getAllUsers() throws Exception {
        return iUserMongoService.getAllUsers();
    }
    /**
     * 修改所有用户信息
     */
    @PostMapping("/update")
    public Response updateUser(@RequestBody UserRegisterCmd userRegisterCmd){
        iUserMongoService.updateUserInfo(userRegisterCmd);
        log.info("数据更新成功");
        return Response.buildSuccess();
    }

    @PostMapping("/delete")
    public Response delete(@RequestBody ReqUserDTO reqUserDTO){
        iUserMongoService.delete(reqUserDTO.getUserId());
        log.info("数据删除成功");
        return Response.buildSuccess();
    }

}
